package com.haiqi.modules.map.service;

import com.haiqi.common.persistence.dao.NavigatWarningMapper;
import com.haiqi.common.persistence.entity.NavigatWarning;
import com.haiqi.common.utils.DateUtils;
import com.haiqi.common.utils.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by hythzx on 2016/6/28.
 */

@Service
public class NavigatWarningService {

    @Autowired
    private NavigatWarningMapper navigatWarningMapper;

    public boolean save(NavigatWarning navigatWarning){
        boolean success = false;
        int i = 0;
        if(StringUtils.isNotEmpty(navigatWarning.getGuid())){  //编辑
            i = navigatWarningMapper.updateByPrimaryKeySelective(navigatWarning);
        }else{  //添加
            navigatWarning.setGuid(UUIDGenerator.getUUID());
            navigatWarning.setPublishtime(DateUtils.dateToString(new Date(),DateUtils.DATETIME_FORMAT));
            navigatWarning.setNtype("2");
            navigatWarning.setState("0");
             i = navigatWarningMapper.insertSelective(navigatWarning);
        }

        if(i > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(NavigatWarning navigatWarning){
        boolean success = false;
        int i = navigatWarningMapper.deleteByPrimaryKey(navigatWarning.getGuid());
        if(i > 0){
            success = true;
        }
        return success;
    }

    public List<NavigatWarning> getDataList(NavigatWarning navigatWarning){
        List<NavigatWarning> navigatWarnings = navigatWarningMapper.select(navigatWarning);
        return navigatWarnings;
    }
//    public boolean saveserver(ShipServer shipServer){
//        boolean result = false;
//        int i = 0;
//        if(StringUtils.isNotEmpty(shipServer.getGuid())){  //编辑
//            i = navigatWarningMapper.updateByPrimaryKeySelective(shipServer);
//        }else{  //添加
//            shipServer.setGuid(UUIDGenerator.getUUID());
//            shipServer.setPublishtime(DateUtils.dateToString(new Date(),DateUtils.DATETIME_FORMAT));
//            shipServer.setNtype("2");
//            shipServer.setState("0");
//            i = navigatWarningMapper.insertSelective(shipServer);
//        }
//
//        if(i > 0){
//            result = true;
//    }
//        return result;
//    }
}
